package com.playball.lottery.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.playball.lottery.R;
import com.playball.lottery.util.LotUtil;
import com.playball.lottery.util.province.GlobalUtils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
 * Created by aa on 2017/5/9.
 */

public class GridviewsAdapter extends BaseAdapter {
    private Context context;
    private Activity activity;
    private String[] string;

    public GridviewsAdapter(Context context, String[] string, Activity activity) {
        this.context = context;
        this.activity = activity;
        this.string = string;
    }

    @Override
    public int getCount() {
        return string == null ? 0 : string.length;
    }

    @Override
    public Object getItem(int i) {
        return string[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GridviewsAdapter.ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.grid_view, viewGroup, false);
            viewHolder.imageView = (ImageView) view.findViewById(R.id.image_view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        ImageLoader.getInstance().displayImage(string[i], viewHolder.imageView, GlobalUtils.getDisplayImageOptions());
        return view;
    }

    private class ViewHolder {
        ImageView imageView;
    }
}
